import { Metadata } from "next";
import { auth } from "~/server/auth";
import { redirect } from "next/navigation";
import LoginForm from "~/components/auth/LoginForm";
import { headers } from "next/headers";

export const metadata: Metadata = {
  title: "登录 - 在线教育平台",
  description: "登录到在线教育平台",
};

export default async function LoginPage() {
  const session = await auth();
  const headersList =await  headers();
  const callbackUrl = headersList.get("referer");

  if (session) {
    if (callbackUrl?.includes("/courses/join/invitation/")) {
      redirect(callbackUrl);
    }
    redirect("/dashboard");
  }

  return (
    <div className="flex min-h-screen items-center justify-center bg-gray-50">
      <LoginForm />
    </div>
  );
}